﻿#pragma once
#include "Reachability.h"
#include "Generation/Engine/Stage/Stage.h"
#include "Generation/Graph/FVertexNode.h"

class Architect
{
private:

	int reflowCount;
	int maxReflowCount = 30;
	//在流淌过程中，可能出现所有路自然堵死情况。这种情况重新生成通路。
	bool failed = false;

public:
	FStage* stage; //建筑师的舞台
	FReachability* reachability;
	
public:

	void InitStage(FStage* _stage);
	void Rebuild(int seed, int vertCount, int minDistance, int maxDistance);

private:

	TArray<FSpanTreeNode*> generatedTree;
	TArray<FSpanTreeNode*> GenerateTree(int vertCount, int minDistance, int maxDistance);
	TArray<FSpanTreeNode*> TryGenerateTree(int vertCount, int minDistance, int maxDistance);

private:
	void ReFlow(TArray<FSpanTreeNode*> tree, int minDistance, int maxDistance);
	void FlowToTarget(FSpanTreeNode* endNode);
	FVec FlowOnce(FVec startTlPos, int targetDepth, FSpanTreeNode* endNode);
	
};
